package com.training.bt.service;

import com.training.bt.entity.PrivateMessage;
import com.training.bt.mapper.PrivateMessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PrivateMessageService implements IPrivateMessageService {
    @Autowired
    private PrivateMessageMapper messageMapper;

    @Override
    public PrivateMessage sendMessage(PrivateMessage message) {
        message.onCreate();
        messageMapper.insert(message);
        return message;
    }

    @Override
    public List<PrivateMessage> getConversation( Long userId1,  Long userId2) {
        return messageMapper.getConversation(userId1, userId2);
    }

    @Override
    public  Long getUnreadMessageCount( Long userId) {
        return messageMapper.countUnreadMessages(userId);
    }

    @Override
    public void markMessagesAsRead( Long userId,  Long senderId) {
        messageMapper.markMessagesAsRead(userId, senderId);
    }
}